/*************************************************************************
	> File Name: main.c
	> Author: 
	> Mail: 
	> Created Time: Thu 28 Nov 2019 12:20:53 AM PST
 ************************************************************************/

#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <string.h>
#include <stdlib.h>
#include <setjmp.h>

#include "shell.h"
#include "env.h"
#include "builtin_cmd.h"

#define UNUSED(x) ((void)x)
static jmp_buf buf;

void signal_handler(int signal_type)
{
    switch (signal_type) {
        case SIGHUP:
            longjmp(buf, 1);
            break;
        //case SIGQUIT:
        //case SIGILL:
        default:
            break;
    }
}

int main(int argc, char *argv[])
{
    int ret = 0;
    struct shell_cmd *shell;

    shell = (struct shell_cmd *)malloc(sizeof(struct shell_cmd));
    
    UNUSED(argc);
    UNUSED(argv);

    init(shell);

    signal(SIGHUP, signal_handler);
    ret = setjmp(buf);

    if (ret != 1)
        run(shell);

    destory(shell);
    system("clear");

    return TURE;
}
